package cn.learn.lombokdemo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * 验证码
 *
 * @author huangyezhan
 * @date 2020年02月18日15:02
 */
@Setter
@Getter
@Accessors(fluent = true)
@ToString
public class ValidateCode {
    /**
     * 验证码
     */
    private String code;

    /**
     * 过期时间（秒）
     */
    private LocalDateTime expireTime;


    /**
     * 是否过期
     *
     * @return 返回判断结果
     */
    public boolean isExpried() {
        return LocalDateTime.now().isAfter(this.expireTime);
    }


    public ValidateCode expireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
        return this;
    }

    public ValidateCode expireTime(int expireTime) {
        this.expireTime = LocalDateTime.now().plusSeconds(expireTime);
        return this;
    }


}
